<!--
/**************************************************
* @ payreceivemanage.jsp
*
* Copyright   2005 Hitrust Technology Inc.
* Developed by SDC, Hitrust.
* All Rights Reserved.
*
* Modify History:
*  v1.00, 2006/02/12, Simonyi Peng
*  1) first release
/**************************************************
-->
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ include file="../../common.jsp" %>
<%@ taglib uri="/page.util.gs.hitrust.com/taglibs/page" prefix="page"%>

<html>
<head>
<title>收付款管理</title>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<LINK href="<%=root%>/css/caigouxitong.css" type=text/css rel=stylesheet>
<SCRIPT language="JavaScript" src="<%=root%>/js/common.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/calendar.js"></SCRIPT>
<SCRIPT language="JavaScript" src="<%=root%>/js/string.js"></SCRIPT>

<%
ArrayList deptList = new ArrayList();
ArrayList addrList = new ArrayList();

ArrayList ary = (ArrayList)request.getAttribute("organdaddr");
deptList = (ArrayList)ary.get(0);
addrList = (ArrayList)ary.get(1);



ArrayList tOffset = (ArrayList)request.getAttribute("offsetlist");
GSPayReceiveQueryVO oaqVO = (GSPayReceiveQueryVO)session.getAttribute("QUERYCONDITION");
%>
<script>
	var counter;
	<%
		//在此作出成功提示
		if(request.getAttribute("SUCCESSMSG") != null)
			out.print("alert('"+request.getAttribute("SUCCESSMSG")+"');");
	%>
	
	
	var deptlist = new Array();
	//初始化
	<%for(int i=0;i<deptList.size();i++){%>
		deptlist[<%=i%>] = '<%=deptList.get(i)%>';
	<%}%>	

	function process(val){

		if(val == 'Q'){
			if(document.all.deptcategory.value == '0'){
				alert("请选择公司类型");return false;
			}
			payreceivequeryform.action = "<%=response.encodeURL(root+"/A180502.do")%>";
    		payreceivequeryform.submit();			
    		return false;
		}
		if(val == 'autopost' || val == 'autostrike' || val == 'handstrike'){
			if(document.all.indexs == null){
				alert("没有此单位的收付款数据！");
				return;
			}
			if(val == 'autopost' ){
				if(!confirm("是否确认执行自动过帐？")){
					return false;
				}
			}				

			if(val == 'autostrike' || val == 'handstrike'){
				if(submitForm.payreceiveNum.value == "" || submitForm.payreceiveNum.value == null){					
					alert("请录入冲销金额");
					return false;
				}
				if(!isFloatNum(submitForm.payreceiveNum.value)){
					alert("请录入正确的冲销金额");
					return false;
				}
				if(submitForm.invoiceNo.value == "" || submitForm.invoiceNo.value == null){
					alert("请录入发票号");
					return false;
				}
				if(submitForm.payDate.value == "" || submitForm.payDate.value == null){
					alert("请录入收款日期");
					return false;
				}
				if(submitForm.principal.value == "" || submitForm.principal.value == null){
					alert("请录入经手人");
					return false;
				}
				if(val == 'autostrike' ){
					if(!confirm("是否确认执行自动冲销？")){
						return false;
					}
				}
				if(val == 'handstrike' ){
					
					var indexs = document.getElementsByName("indexs");
					var isSelected = false;
					for(i=0;i<indexs.length;i++){
						if(indexs[i].checked )
							isSelected = true;
					}
					if(isSelected != true) {
						alert("请至少选择一笔应收应付款");
						return false;
					}

					if(!confirm("是否确认执行手工冲销？")){
						return false;
					}

				}
			}
			submitForm.action = "<%=response.encodeURL(root+"/A180503.do")%>";
			submitForm.actionvalue.value=val;
			submitForm.submit();
		}
	}
	
	function cls(){
		
	}	
	
	function exchangeDept(){
		var category = document.getElementById("deptcategory").value;
		if(category == "0"){
			return false;
		}
		if(category == "1"){
			document.getElementById("isProv").style.display = 'none';
			document.getElementById("isDept").style.display = '';
		}
		if(category == "2"){
			document.getElementById("isDept").style.display = 'none';
			document.getElementById("isProv").style.display = '';
		}
	}
	
	function requery(){
		<%if("true".equals((String)request.getAttribute("requery"))){%>
			process('Q');
		<%}%>
	}
</script>
</head>
<body BGCOLOR="#f5f5f5"	text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="requery();" >

<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td height="20"> 
      <table width="100%" border="0" cellspacing="0" cellpadding="1">
        <tr height="20">
          <td height="20" width="1" class="mtxt_black">&nbsp;</td>
          <td height="30" width="758" class="mtxt_black">收付款管理</td>
        </tr>
      </table>
    </td>
  </tr>
  <tr>
    <td class="bg_line" height="2"></td>
  </tr>
</table>

<br>


<form name="payreceivequeryform" method="get" >

<table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr> 
		<td> 
			<table class=bg_table id=tableId	cellspacing=1 cellpadding=0 style="padding-left:5;padding-right:5" width=100% align=center border=0>
				<TR height=20>
					<TD class="bg_column" align=center>公司类型</TD>
					<TD left=left class="bg_row_odd">
				        <select id='deptcategory' name='deptcategory' onChange='exchangeDept()'>
				        	<option value="0" selected>--请选择--</option>
							<option value="1" <%if(oaqVO!=null && "1".equals(oaqVO.deptcategory)) out.print("selected");%>>订货单位</option>
							<option value="2" <%if(oaqVO!=null && "2".equals(oaqVO.deptcategory)) out.print("selected");%>>供应商</option>
                       	</select>
					</TD>					
					<TD class="bg_column" align=center>公司名称</TD>
					<TD align=left class="bg_row_odd">
					<div id='isProv' >
						<input type="text" name="provname" maxlength="20" value="<%=oaqVO==null?"":(oaqVO.provName==null?"":oaqVO.provName)%>">
					</div>
					<div id='isDept' style='display:none'>
						<select name="deptid">
                    		<%
                    		for(int i=0;i<deptList.size();i++){
                    			String dept = (String)deptList.get(i);
						        StringTokenizer st = new StringTokenizer(dept,"|");
						        String[] tmp = new String[2] ;
						        int index =0;
						        while(st.hasMoreElements()){
						            tmp[index++] = (String)st.nextElement();
						        }
                    		%>
                        		<option value='<%=tmp[0]%>' <%if(tmp[0].equals(oaqVO==null?"":(oaqVO.deptId==null?"":oaqVO.deptId))) out.print("selected");%>><%=tmp[1]%></option>
                    		<%
                    		}
                    		%>					
						</select>
					</div>
					</TD>					
				</TR>
			</table>
           	<%if(oaqVO!=null && "1".equals(oaqVO.deptcategory)) out.print("<SCRIPT LANGUAGE='JAVASCRIPT'>exchangeDept();</SCRIPT>");%>
		</td>
	</tr>
</table>
</form>
    <p align="center">  
		<input type="button" width="58" class="kuang" height="24" value="查询" onclick="process('Q')"/>&nbsp;
		<input type="button" width="58" class="kuang" height="24" value="清空" onclick="cls()"/>
    </p>
<%
	
	if(tOffset != null){
%>

<form name='submitForm' method="post">


	<center>
    <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
		<tr>
			<td>
            <%
            String workcorpid = "";
			%>			

            	<table class=bg_table id=tableId	cellspacing=1 cellpadding=2 width=100% align=center border=0>
                    <tbody> 
                    <tr class="bg_column" height=20> 
                    	<td></td>
                        <td class=top align=middle> 
                        <div align="center" class="txt_content">公司名称</div>
						</td>
                        <td class=top align=middle> 
                        <div align="center" class="txt_content">费用类型</div>
						</td>
                        <td class=top align=middle> 
                        <div align="center" class="txt_content">收（付）款类型</div>
						</td>
                        <td class=top align=middle> 
                        <div align="center" class="txt_content">剩余金额（元）</div>
						</td>									
						<td class=top align=middle> 
                        <div align="center" class="txt_content">收（付）款日期</div>
						</td>									
						<td class=top align=middle> 
                        <div align="center" class="txt_content">负责（联系）人</div>
						</td>									
					</tr>
					<%
						
						if(tOffset != null && tOffset.size() > 0){
						for(int i=0; i<tOffset.size(); i++){
							GSPayReceiveListVO vo = (GSPayReceiveListVO)tOffset.get(i);
							workcorpid = vo.workcorpid;
							String tTempStr="";
							if(i%2==0){
								tTempStr="class=\"bg_row_odd\"";
							}else {
								tTempStr="class=\"bg_row_even\"";
							}
							int size = 0;
					%>
							<tr <%=tTempStr%> height=20>
								<td class=top align=middle rowspan="<%=size %>"> 
									<div align="center" class="txt_content">
									<input type="checkbox" id="indexs<%=i%>" name="indexs" onClick='calculate(<%=i%>)' value="<%=vo.receiveableid%>" >
									</div>
								</td>			
								<td class=top align=middle rowspan="<%=size %>" nowrap> 								
									<div align="center" class="txt_content">
									<%=vo.deptname%>
									</div>
								</td>	
								<td class=top align=middle rowspan="<%=size%>"> 
									<div align="center" class="txt_content">
									<%=vo.feetypenoValue%>
									</div>
								</td>	
								<td class=top align=middle rowspan="<%=size %>"> 								
									<div align="center" class="txt_content">
									<%="1".equals(vo.paytype)?"收款":"付款"%>
									</div>
								</td>	
								<input type='hidden' id='paytype_<%=i%>' value = <%=vo.paytype%>>
								<td class=top align=middle rowspan="<%=size %>"> 								
									<div align="center" class="txt_content">
									<%=StringUtils.format(vo.balanceundone,4)%>
									</div>
								</td>	
								<input type='hidden' id='balanceundone<%=i%>' value='<%=Double.parseDouble(vo.balanceundone) * ("1".equals(vo.paytype)?1:-1)%>'>
								<td class=top align=middle rowspan="<%=size %>"> 								
									<div align="center" class="txt_content">
									<%=vo.paydate%>
									</div>
								</td>	
								<td class=top align=middle nowrap> 
									<div align="center" class="txt_content">
									<%=vo.principal%>
									</div>
								</td>
							</tr> 
					<%	
							
							}
						}else{
					%>
							<font color="red">没有符合条件的应收应付信息,请重新输入查询条件</font>
					<%
						}
					%>
					</tbody>
				</table>

			</td>
		</tr>
	</table>
	</center>
<input type='hidden' name='workcorpcategory' value='<%=oaqVO==null?"":oaqVO.deptcategory%>'>
<input type='hidden' name='deptcode' value='<%=workcorpid%>'>
<input type='hidden' name='actionvalue' value=''>
	<br>

	<center>
    <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
		<tr>
			<td>
            <%
			%>			

            	<table class=bg_table id=tableId	cellspacing=1 cellpadding=2 width=100% align=center border=0>
                    <tbody> 
                    <tr  height=20> 
                        <td class="bg_column" align=middle> 
                        <div align="center" class="txt_content">类型</div>
						</td>
						<td class="bg_row_odd" align=middle colspan=3> 
                        <div align="left" class="txt_content">
                        <select name='payreceiveType'>
                        	<option value='1'>收款</option>
                        	<option value='2'>付款</option>
                        </select>
                        </div>
						</td>
					</tr>
					<tr  height=20> 
                        <td class="bg_column" align=middle> 金额（元）</td>
                        <td class="bg_row_odd" align=left><input type='text' name='payreceiveNum' calss='kuang'>&nbsp;<font color='red'>*</font></td>
                        <td class="bg_column" align=middle> 冲销金额（元）</td>
                        <td class="bg_row_odd" align=left><input type='text' id='strikeNum' name='strikeNum' calss='kuang' value='0' readonly></td>
					</tr>
					<tr  height=20> 
                        <td class="bg_column" align=middle> 发票信息</td>
						<td class="bg_row_odd" align=left> 
                        	<input type='radio' name='invoiceMsg' value='K' checked>已开具发票&nbsp;&nbsp;
                        	<input type='radio' name='invoiceMsg' value='S'>已收取发票
						</td>									
						<td class="bg_column" align=middle> 发票号</td>
						<td class="bg_row_odd" align=left>
							<input type='text' name='invoiceNo' calss='kuang'>&nbsp;<font color='red'>*</font>
						</td>
					</tr>
					<tr  height=20> 
                        <td class="bg_column" align=middle> 收款日期</td>
                        <td class="bg_row_odd" align=left><input type='text' name='payDate' calss='kuang' readonly onfocus='setday(this)'>&nbsp;<font color='red'>*</font></td>
                        <td class="bg_column" align=middle> 经手人</td>
                        <td class="bg_row_odd" align=left><input type='text' name='principal' calss='kuang'>&nbsp;<font color='red'>*</font></td>
					</tr>
					<tr  height=20> 
                        <td class="bg_column" align=middle> 备注</td>
                        <td class="bg_row_odd" align=left colspan=3> 
							<textarea id="auditcontent" name ="notes" style="WIDTH: 100%; HEIGHT: 50px" name="notes"></textarea>                        
                        </td>
					</tr>
					
					</tbody>
				</table>

			</td>
		</tr>
	</table>
	</center>

	<p align="center">  
    	<input type="button" class="kuang" value="自动过账" onclick="process('autopost')">
    	<input type="button" class="kuang" value="自动冲销" onclick="process('autostrike')">
    	<input type="button" class="kuang" value="手工冲销" onclick="process('handstrike')">
    </p>
    <br>
    <br>
    
</form>    
<%		
	}
	if(tOffset == null && request.getAttribute("requery") != null && request.getAttribute("requery").equals("true")){
%>
		<font size="2">数据查询中......</font>
<%
	}
%>

<script language='javascript'>
function calculate_old(index){
	var OnOff = document.getElementById("indexs"+index).checked; 
		var stkm = parseFloat(document.all.strikeNum.value);
		var add = parseFloat(document.getElementById("balanceundone"+index).value);
	var middleValue = 0;
	if(OnOff){
		middleValue = Math.abs(stkm + add);
	}
	else{
		middleValue = Math.abs(stkm - add);
	}
	alert(middleValue.toFixed(4));
	document.all.strikeNum.value = middleValue.toFixed(4);
}

function calculate(index){
	var indexs = document.getElementsByName("indexs");
	var zero = 0;
	for(var i=0;i<indexs.length;i++){
		var onoff = indexs[i].checked;
		if(onoff){
			zero  = zero - parseFloat(document.getElementById("balanceundone"+i).value);
		}
	}
	document.all.strikeNum.value = Math.abs(zero).toFixed(4);
}

</script>
</body>
</html>